<template>
  <div class="ma-content-block lg:flex justify-between p-4">
    <!-- CRUD 组件 -->
    <ma-crud :options="options" :columns="columns" ref="crudRef">
    </ma-crud>
  </div>
</template>
<script setup>
import {ref, reactive} from 'vue'
import plugin from '@/api/backend/plugin.js'
import {Message} from '@arco-design/web-vue'
import tool from '@/utils/tool.js'
import * as common from '@/utils/common.js'

const crudRef = ref()


const numberOperation = (newValue, id, numberName) => {
  plugin.numberOperation({id, numberName, numberValue: newValue}).then(res => {
    res.success && Message.success(res.message)
  }).catch(e => {
    console.log(e)
  })
}

const switchStatus = (statusValue, id, statusName) => {
  plugin.changeStatus({id, statusName, statusValue}).then(res => {
    res.success && Message.success(res.message)
  }).catch(e => {
    console.log(e)
  })
}


const options = reactive({
  id: 'plugin_plugin',
  rowSelection: {
    showCheckedAll: true
  },
  pk: 'id',
  operationColumn: true,
  operationColumnWidth: 160,
  formOption: {
    viewType: 'drawer',
    width: 900
  },
  api: plugin.getList,
  recycleApi: plugin.getRecycleList,
  add: {
    show: true,
    api: plugin.save,
    auth: ['plugin::save']
  },
  edit: {
    show: true,
    api: plugin.update,
    auth: ['plugin::update']
  },
  delete: {
    show: true,
    api: plugin.deletes,
    auth: ['plugin::delete'],
    realApi: plugin.realDeletes,
    realAuth: ['plugin::realDeletes']
  },
  recovery: {
    show: true,
    api: plugin.recoverys,
    auth: ['plugin::recovery']
  }
})

const columns = reactive([
  {
    title: "ID",
    dataIndex: "id",
    formType: "input",
    addDisplay: false,
    editDisplay: false,
    hide: true,
    commonRules: {
      required: true,
      message: "请输入主键"
    }
  },
  {
    title: "创建时间",
    dataIndex: "created_at",
    formType: "date",
    addDisplay: false,
    editDisplay: false,
    showTime: true
  },
  {
    title: "更新时间",
    dataIndex: "updated_at",
    formType: "date",
    addDisplay: false,
    editDisplay: false,
    showTime: true
  },
  {
    title: "删除时间",
    dataIndex: "deleted_at",
    formType: "date",
    addDisplay: false,
    editDisplay: false,
    hide: true,
    showTime: true
  },
  {
    title: "分类",
    dataIndex: "category_id",
    formType: "select",
    multiple: false,
    dict: {
      remote: "backend/pluginCategory/remote",
      openPage: false,
      props: {label: 'name', value: 'id'},
      remoteOption: {
        sort: {id: 'desc'},
        select: ['name', 'id']
      },
      translation: true
    }
  },
  {
    title: "类型",
    dataIndex: "type",
    formType: "select",
    dict: {
      data: [
        {
          label: "企业插件",
          value: "1"
        },
        {
          label: "项目插件",
          value: "2"
        },
        {
          label: "通用插件",
          value: "3"
        }
      ],
      translation: true
    },
    search: true
  },
  {
    title: "插件名称",
    dataIndex: "name",
    formType: "input",
    search: true
  },
  {
    title: "副标题",
    dataIndex: "subtitle",
    formType: "input",
    hide: true
  },
  {
    title: "Icon",
    dataIndex: "icon",
    formType: "upload",
    type: "image",
    multiple: false
  },
  {
    title: "跳转路径",
    dataIndex: "path",
    formType: "input",
  },
  {
    title: "跳转路径",
    dataIndex: "path_type",
    formType: "select",
    dict: {
      data: [
        {
          label: "内部路径",
          value: "1"
        },
        {
          label: "h5页面路径",
          value: "2"
        }
      ],
      translation: true
    }
  },
  {
    title: "状态",
    dataIndex: "status",
    formType: "select",
    dict: {
      data: [
        {
          label: "显示",
          value: "1"
        },
        {
          label: "隐藏",
          value: "2"
        }
      ],
      translation: true
    }
  },
  {
    title: "仅管理员可见",
    dataIndex: "only_admin",
    formType: "select",
    dict: {
      data: [
        {
          label: "否",
          value: "0"
        },
        {
          label: "是",
          value: "1"
        }
      ],
      translation: true
    }
  },
  {
    title: "模型",
    dataIndex: "model_code",
    formType: "select",
    addDefaultValue: "default",
    dict: {
      remote: 'base/model/remote',
      method: 'post',
      props: {label: 'name', value: 'code'},
      remoteOption: {
        select: ['name', 'code'],
        filter: {
          type: ['=', 1]
        }
      },
      translation: true
    }
  },
  {
    title: "排序",
    dataIndex: "sort",
    formType: "input-number"
  },
  {
    title: "使用文档",
    dataIndex: "doc_url",
    formType: "input"
  },
  {
    title: "下载数量",
    dataIndex: "download_num",
    formType: "input-number"
  },
  {
    title: "收费",
    dataIndex: "is_fee",
    formType: "select",
    dict: {
      data: [
        {
          label: "否",
          value: "0"
        },
        {
          label: "是",
          value: "1"
        }
      ],
      translation: true
    }
  },
  {
    title: "费用",
    dataIndex: "fee",
    formType: "input-number"
  },
  {
    title: "功能介绍",
    dataIndex: "introduce",
    formType: "editor",
    hide: true
  }
])
</script>
<script> export default {name: 'plugin'} </script>